@extends('admin.common.common')
@section('title')
文章管理
@endsection
@section('content')
<div class="container-fluid main py-2 bg-light my-4">
    <div class="row">
      <div class="col-md-2">
        <div class="sidebar bg-dark">
          <ul>
            <li><a href="{{url('/admin/user/index')}}">用户管理</a></li>
            <li><a href="#">角色管理</a></li>
            <li><a href="#">权限管理</a></li>
            <li class="more active"><a href="{{url('/admin/article/index')}}">文章管理</a></li>
          </ul>
        </div>
      </div>
      <div class="col-md-9 offset-md-1">
        <div class="content">
          <h2 class="my-2">文章管理</h2>
          <a href="{{url('/admin/article/add')}}" class="btn btn-success my-2">添加文章</a>
          <table class="table">
            <thead>
              <tr>
                <th>id</th>
                <th>标题</th>
                <th>关键字</th>
                <th>作者</th>
                <th>发布时间</th>
                <th>更新时间</th>
                <th>操作</th>
              </tr>
            </thead>
            <tbody>
              @foreach($articles as $article)
              <tr>
                <td>{{$article -> id}}</td>
                <td>{{$article -> title}}</td>
                <td>
                @foreach(explode(',',$article -> keyword) as $keyword)
                  <span class="badge badge-primary">{{$keyword}}</span>
                @endforeach
                </td>
                <td>{{$article -> user->uname}}</td>
                <td>{{$article -> created_at}}</td>
                <td>{{$article -> updated_at}}</td>
                <td>
                  <a href="javascript: ;" class="del">删除</a> | 
                  <a href="{{url('/admin/article/edit/'.$article->id)}}">编辑</a> | 
                  <a href="{{url('/admin/article/display/'.$article->id)}}">查看</a>
                </td>
              </tr>
              @endforeach
            </tbody>
          </table>
          <div class="float-right">{{$articles->links()}}</div>
        </div>
      </div>
    </div>
  </div>
@endsection
@section('script')
$('.del').click(function(){
  var that = $(this);
  layui.use('layer', function(){
    var layer = layui.layer;
    layer.confirm('你确定要删除 '+that.parent().parent().find('td').eq(1).html()+' ?', {icon: 3, title:'提示'}, function(index){
      layer.close(index);

      var id = that.parents('tr').children().first().html();
      that.parents('tr').remove();
      console.log(id);
      $.get('{{url("/admin/article/del/")}}/'+id,[], function($data) {
        if($data)  {
          layer.msg('删除成功',{icon:1});
        }
      })
    });
  });  
})

@endsection
